package com.kobeliu.controller;

import com.google.gson.Gson;
import com.kobeliu.api.interceptor.JwtCurrentUserInterceptor;
import com.kobeliu.base.BaseInfoProperties;
import com.kobeliu.pojo.Users;
import com.kobeliu.result.GraceJSONResult;
import com.kobeliu.result.IMOOCJSONResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("hello")
@Slf4j
public class HelloController extends BaseInfoProperties {

    @RequestMapping(method = RequestMethod.GET,path = "/haha")
    public GraceJSONResult hello(HttpServletRequest request){

        //不从request中拿 使用threadLocal
//        String userJson = request.getHeader(APP_USER_JSON);
//
//        //获取请求头中的users用户对象
//        Users users = new Gson().fromJson(userJson, Users.class);

        //从ThreadLocal中获取对象
        Users users = JwtCurrentUserInterceptor.currentUser.get();
        log.info("获取的user对象：{}=============",users);


        return GraceJSONResult.ok();
    }
}
